﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CMN.Entity;
using CMN.Common;
using CMN.Framework;
using CMN.BLL;
namespace CMN.UI
{
    /// <summary>
    /// 标签解析
    /// </summary>
    public class Normal_ZTDisplay
    {
       
        static Normal_ZTDisplay()
        {
            BaseTemplateDisplay.OnNVelocityLoadPath += new EventHandler<TemplateArg>(ZTLoadPath);
            BaseTemplateDisplay.OnAfterBaseDisplay += new EventHandler<TemplateDisplayArg>(ZTList);
            BaseTemplateDisplay.OnOtherPageDisplay += new EventHandler<TemplateDisplayArg>(ZTDisplay);
        }

        /// <summary>
        /// 绑定模板
        /// </summary>
        /// <param name="o"></param>
        /// <param name="arg"></param>
        private static void ZTDisplay(object o, TemplateDisplayArg arg)
        {
            if (arg.PageHelper.OtherTypeName == "zt")
            {
                Normal_ZTDisplay ZT = new Normal_ZTDisplay();

                arg.NvelocityTemplate.Put("ztDisplay", ZT);
            }
           
        }

        /// <summary>
        /// 加载模板路径
        /// </summary>
        /// <param name="o"></param>
        /// <param name="arg"></param>
        private static void ZTLoadPath(object o, TemplateArg arg)
        {
            if (arg.PageHelper.OtherTypeName == "zt")
            {
                Normal_ZTEntity ZTEntity = (Normal_ZTEntity)arg.PageHelper.OtherEntity;
                //AppLog.Write("ZTEntity.TemplateId" + ZTEntity.TemplateId.ToString(), AppLog.LogMessageType.Error);
                if (ZTEntity != null)
                {
                    if (ZTEntity.TemplateId != 0)
                    {
                        
                      Normal_TemplateListEntity templateeListEntity = MvcWebCacheManager.GetTemlateListEntity(ZTEntity.TemplateId);

                     
                        arg.TemplateEntity = MvcWebCacheManager.GetTemlateEntity(templateeListEntity.TemplateId);
                      
                        arg.TemplateEntity.TemplateName = templateeListEntity.TemplateName;
                      
                    }
                    else
                    {
                        arg.TemplateEntity = MvcWebCacheManager.GetDefaultTemlateEntity();
                        arg.TemplateEntity.TemplateName = "zt/zt.htm";
                    }

                }
              
            }

        }
        /// <summary>
        /// 绑定模板
        /// </summary>
        /// <param name="o"></param>
        /// <param name="arg"></param>
        private static void ZTList(object o, TemplateDisplayArg arg)
        {
            if (arg.PageHelper.OtherTypeName == "zt")
            {

                Normal_ZTEntity ZTEntity = (Normal_ZTEntity)arg.PageHelper.OtherEntity;
                if (ZTEntity != null)
                {

                    arg.NvelocityTemplate.Put("ztEntity", ZTEntity);

                }
                else
                {
                    ZTEntity = new Normal_ZTEntity();
                    arg.NvelocityTemplate.Put("ztEntity", ZTEntity);
                    AppLog.Write("ZTDisplay:" + arg.PageHelper.ContentId + "为空 ", AppLog.LogMessageType.Debug);
                }

            }
           
        }
       

        /// <summary>
        /// 获取标签列表
        /// </summary>
        /// <param name="showNum"></param>
        /// <param name="cacheTime"></param>
        /// <returns></returns>
        public List<Normal_ZTMapEntity> List(Int32 ztId, Int32 orderNum, Int32 pageSize)
        {

            List<Normal_ZTMapEntity> ztMapList = new List<Normal_ZTMapEntity>();
            QueryParam qp = new QueryParam();
            qp.PageIndex = 1;
            qp.PageSize = pageSize;
            qp.Where = string.Concat("PId=", ztId.ToString()," ");
            if (orderNum >0)
            {
                qp.Where = string.Concat(qp.Where, " and ordernum=", orderNum.ToString());
            }
            Normal_ZTMap ztMapBll = new Normal_ZTMap();
            int recourdNum=0;
            ztMapList= ztMapBll.List(qp, out recourdNum);
            return ztMapList;
        }

        
    }

}
